let express = require('express'),
    app = express();
// 配置cors跨域
app.use((req, res, next) => {
    // 允许的域
    res.header("Access-Control-Allow-Origin", "http://127.0.0.1:5500");
    // res.header("Access-Control-Allow-Origin", "*"); // 允许任何域
    // 允许凭证
    res.header("Access-Control-Allow-Credentials", true);
    // 允许表头
    res.header("Access-Control-Allow-Headers", "Content-Type, Content-Length, Authorization, Accept, X-Requested-With");
    // 
    res.header("Access-Control-Allow-Methods", "PUT, POST, GET, DELETE, HEAD, OPTIONS");
    if (req.method === 'OPTIONS') {
        res.send('OK!');
        return;
    }
    next();
})
app.listen(8000, _ => {
    console.log('服务器启动成功');
    console.log('http://127.0.0.1:8000');
});
app.get('/cors', (req, res) => {
    res.send(`GET http://127.0.0.1:8000/cors`);
})
app.post('/submit', (req, res) => {
    res.send(`POST http://127.0.0.1:8000/submit`);
})